package xml;

import java.beans.XMLDecoder;
import java.beans.XMLEncoder;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * @author oldliu
 * @since 1.0
 */
public class SuperMarket implements Serializable {
    private String name;
    private String address;
    private List<Member> vips=new ArrayList<>();

    public static final String FILE_NAME="supermarket.xml";

    //set get
    //从文件中获得一个超市对象；如果不存在，创建一个对象
    public static SuperMarket getFromXML(){
        try {
            XMLDecoder xd=new XMLDecoder(new FileInputStream(FILE_NAME));
            SuperMarket m= (SuperMarket)xd.readObject();
            xd.close();
            return m;
        } catch (Exception e) {
            //e.printStackTrace();
        }
        //System.out.println("请输入超市的名字和地址：");

        return null;
    }
    public static void store(SuperMarket m){
        try {
            XMLEncoder xm=new XMLEncoder(new FileOutputStream(FILE_NAME));
            xm.writeObject(m);
            xm.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
